package com.karst.essentials.chapter03
{
	import flash.events.Event;
	
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.view.BasicView;
	
	internal class VerticesExample extends BasicView
	{
		public function VerticesExample()
		{
			super() ;
			createView() ;
			startRendering() ;
		}

		private var do3d : DisplayObject3D = null ;
		private var sphere : Sphere = null ;
		private function createView() : void
		{
			if( do3d == null )
				do3d = new DisplayObject3D() ;
			
			if( sphere == null )
				sphere = new Sphere( null, 400, 16, 12 ) ;
			
			var num : uint = sphere.geometry.vertices.length ;
			for( var i : uint = 0 ; i < num; i++ )
			{
				var child : Sphere = new Sphere( null, 25, 3, 2 ) ;
				do3d.addChild( child ) ;
				child.x = sphere.geometry.vertices[i].x ;
				child.y = sphere.geometry.vertices[i].y ;
				child.z = sphere.geometry.vertices[i].z ;
			}
			
			scene.addChild( do3d ) ;
		}
		
		override protected function onRenderTick(event:Event=null):void
		{
			super.onRenderTick() ;
			if( do3d )
				do3d.localRotationX++ ;
				do3d.localRotationY += 2 ;
				do3d.localRotationZ++ ;
		}
	}
}